package com.yuyou.tas.terminal.controller;

import com.yuyou.tas.service.api.admin.entity.CommDataConfig;
import com.yuyou.tas.service.api.lesson.entity.BaseLevel;
import com.yuyou.tas.service.api.lesson.entity.BaseSchool;
import com.yuyou.tas.service.api.lesson.entity.BaseSection;
import com.yuyou.tas.service.api.lesson.entity.BaseTrimester;
import com.yuyou.tas.service.api.lesson.service.BaseDataAPI;
import com.yuyou.tas.service.api.lesson.service.CommDataConfigAPI;
import com.yuyou.tas.util.bean.ReturnResult;
import com.yuyou.tas.util.enums.admin.CommDataConfigEnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(value="YyfnMCommController",description="通用接口")
@Validated
@RestController
@RequestMapping(value = "/api/m/comm")
public class YyfnMCommController extends BaseController{

	@Autowired
	private BaseDataAPI baseDataAPI;
	
	@Autowired
	private CommDataConfigAPI commDataConfigAPI;
		
	@ApiOperation(value = "查询所在机构的学期")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "sysCode", value = "机构编号", paramType = "query", required = true)})
	@RequestMapping(value = "/findTrim", method = { RequestMethod.GET,
			RequestMethod.POST })
	public ReturnResult<List<BaseTrimester>> findTrim(@NotBlank(message = "机构编号不能为空") String sysCode) throws Exception {
		Long authOrganizationId=this.getOrganId(sysCode);
		List<BaseTrimester> list = baseDataAPI.findTrimByOran(authOrganizationId);		
		return ReturnResult.success(list);
	}

	@ApiOperation(value = "查询所在机构的班型")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "sysCode", value = "机构编号", paramType = "query", required = true)})
	@RequestMapping(value = "/findLevel", method = { RequestMethod.GET,
			RequestMethod.POST })
	public ReturnResult<List<BaseLevel>> findLevel(
			HttpServletRequest request,
			@NotBlank(message = "机构编号不能为空") String sysCode) throws Exception {
		Long authOrganizationId=this.getOrganId(sysCode);
		List<BaseLevel> baseList=baseDataAPI.findBaseLevelByOrganId(authOrganizationId);
		return ReturnResult.success(baseList);
	}
	
	@ApiOperation(value = "查询所在机构的年级")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "sysCode", value = "机构编号", paramType = "query", required = true)})
	@RequestMapping(value = "/findSection", method = { RequestMethod.GET,
			RequestMethod.POST })
	public ReturnResult<List<BaseSection>> findSection(
			HttpServletRequest request,
			@NotBlank(message = "机构编号不能为空") String sysCode) throws Exception {
		List<BaseSection> bs=baseDataAPI.findBaseSection();
		return ReturnResult.success(bs);
	}
	
	@ApiOperation(value = "查询所在机构的校区")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "sysCode", value = "机构编号", paramType = "query", required = true)})
	@RequestMapping(value = "/findSchool", method = { RequestMethod.GET,
			RequestMethod.POST })
	public ReturnResult<List<BaseSchool>> findSchool(
			HttpServletRequest request,
			@NotBlank(message = "机构编号不能为空") String sysCode) throws Exception {
		Long authOrganizationId=this.getOrganId(sysCode);
		List<BaseSchool> baseSchoolList=baseDataAPI.getSchoolByOrganId(authOrganizationId);		
		return ReturnResult.success(baseSchoolList);
	}
	
	@ApiOperation(value = "查询所在机构的科目")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "sysCode", value = "机构编号", paramType = "query", required = true)})
	@RequestMapping(value = "/findSubject", method = { RequestMethod.GET,
			RequestMethod.POST })
	public ReturnResult<List<BaseSchool>> findSubject(
			HttpServletRequest request,
			@NotBlank(message = "机构编号不能为空") String sysCode) throws Exception {
		Long authOrganizationId=this.getOrganId(sysCode);
		List<CommDataConfig> list=commDataConfigAPI.findUseByCategory(CommDataConfigEnums.category.subject.getValue());
		return ReturnResult.success(list);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}
